package com.test.t1;

import com.test.bean.Person;
import com.test.config.MainConfigPropertiesValue;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Arrays;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/29 9:09
 */
public class IocTest_Value {
    @Test
    public void test01() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfigPropertiesValue.class);
        printBeans(context);
        Person person = context.getBean(Person.class);
        System.out.println(person);

        ConfigurableEnvironment environment = context.getEnvironment();
        String property = environment.getProperty("person.nickName");
        System.out.println(property);
    }

    private void printBeans(AnnotationConfigApplicationContext context) {
        String[] definitionNames = context.getBeanDefinitionNames();
        Arrays.stream(definitionNames).forEach(System.out::println);
    }
}
